package com.example.app.util

import com.example.app.service.Api
import org.apache.commons.logging.LogFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
import java.text.SimpleDateFormat
import java.util.*


/**
 * Created by http://quanke.name on 2018/1/12.
 */
@Component
class ScheduledTasks {
    val log = LogFactory.getLog(ScheduledTasks::class.java)!!

    private val dateFormat = SimpleDateFormat("HH:mm:ss")
    
    @Autowired
    internal var api: Api? = null

    @Scheduled(fixedRate = 1000)
    fun reportCurrentTime() {
        val time = dateFormat.format(Date())
        log.info("现在时间 , $time")
        if ("22:30:00" == time || "23:30:00" == time) {
            api!!.saveNewData()
        }
    }
}